package com.jcfk.eam.util.bean.codeParse;

import lombok.Data;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Data
public class MouldCodeParse implements CodeParse {

    private String materialCode;
    private String projectCode;
    private String finishedDate;
    private String serial;

    private static String pattern = "(?<materialCode>[\\d]{7})" +
            "(?<projectCode>[\\d]{4})" +
            "(?<finishedDate>[\\d]{8})" +
            "(?<serial>[\\d]{3})";
    Pattern compile = Pattern.compile(pattern);
    @Override
    public CodeParse parse(String code) {
        Matcher matcher = compile.matcher(code);
        if (matcher.find()){
            this.materialCode = matcher.group("materialCode");
            this.projectCode = matcher.group("projectCode");
            this.finishedDate = matcher.group("finishedDate");
            this.serial = matcher.group("serial");
            return this;
        }
        return null;
    }

    @Override
    public Boolean matcher(String code) {
        Matcher matcher = compile.matcher(code);
        return matcher.find();
    }
}
